package fr.enseirb.mycub.activity.component.slidingmenu;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import fr.enseirb.mycub.R;

public class SampleAdapter extends BaseAdapter {
	
	Context context;
	ArrayList<SlidingMenuItem> items;
	
	public SampleAdapter(Context context, ArrayList<SlidingMenuItem> items) {
		super();
		this.context = context;
		this.items = items;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		final SlidingMenuItem item = (SlidingMenuItem) getItem(position);
		if (convertView == null) {
			if(item.isLayer)convertView = LayoutInflater.from(context).inflate(R.layout.slidingmenu_row_checkbox, null);
			else convertView = LayoutInflater.from(context).inflate(R.layout.slidingmenu_row, null);
		}
		ImageView icon = (ImageView) convertView.findViewById(R.id.row_icon);
		icon.setImageResource(item.iconRessource);
		TextView title = (TextView) convertView.findViewById(R.id.row_title);
		title.setText(item.name);
		if(item.isLayer){
		CheckBox cb = (CheckBox) convertView.findViewById(R.id.row_checkBox);
		cb.setChecked(item.checked);
		}
		convertView.setTag(item);

		return convertView;
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

}